<template>
  <div>
    <router-link tag='div' class="header-abs" to='/' v-show='showAbs'>
      <div class='iconfont header-abs-back'>&#xe661;</div>
    </router-link>
    <div class="header-fixed" v-show='!showAbs' :style='opacityStyle'>
      <router-link
        tag='div' to='/'
        class='iconfont header-fixed-back'
      >&#xe6b4;
      </router-link>
      <span>景点详情</span>
    </div>
  </div>
</template>

<script>
export default{
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      console.log('scroll')
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        this.opacityStyle = {opacity: opacity}
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.addEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang = 'stylus' scoped>
  @import '~styles/varibles.styl'
  .header-abs
    position:fixed
    top:.1rem
    left:.1rem
    height:1rem
    width:1rem
    .header-abs-back
      font-size:.6rem
  .header-fixed
    display: flex
    justify-content: center;
    position:fixed
    top:0
    left:0
    right:0
    height:1rem
    line-height:1rem
    font-size: .35rem
    color: white;
    background: $bgColor
    .header-fixed-back
      position: absolute
      left: .1rem
      font-size: 0.45rem
</style>
